package com.es.gateway.一砂云.港澳公民实人三要素;

import com.es.gateway.sdk.ESGateway;
import com.es.gateway.sdk.app.identity_auth_3.IdentityAuth3Request;
import com.es.gateway.sdk.app.identity_auth_3.IdentityAuth3Response;
import com.es.gateway.sdk.constant.AlgorithmE;
import com.es.gateway.sdk.entity.GatewayResponse;
import com.es.gateway.sdk.util.B64Util;
import com.es.gateway.sdk.util.ResourceUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * 非大陆公民实人三要素校验, 参考: https://esandinfo.yuque.com/yv6e1k/aa4qsg/qxldzt
 */
@Slf4j
public class IdentityAuthTester {
    /**
     * 港澳台公民实名三要素: https://esandinfo.yuque.com/yv6e1k/aa4qsg/qxldzt
     */
    @Test
    public void test() {
        String appCode = "d2808c1338ce01f3e3efdb486f9effb9";
        AlgorithmE algo = AlgorithmE.MD5;
        String key = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhdQdw6uTGz+X4e+/eGpu4dcKrfrjQAe0tTQyn6TuKBobcsUsESkx9jcCeG4cpuxmN8jNeDAZsbTujNLD/aYl2g==";
        ESGateway esGateway = new ESGateway(appCode, algo, key);

        IdentityAuth3Request request = new IdentityAuth3Request();
        request.setNation("CHN");
        request.setIdType("1");
        request.setName("李晨");
        request.setIdNO("H60511121");
        byte[] imgBuff = new ResourceUtil().loadResource("cn_idcard.jpeg");
        String imgBase64Str = B64Util.encodeStr(imgBuff);
        request.setPersonImg(imgBase64Str);
        GatewayResponse gatewayResponse = esGateway.sendToGateWay(IdentityAuth3Request.act, request.toJsonStr());
        log.info("服务器端返回: {}", gatewayResponse.toJsonStr());
        if (gatewayResponse.getBizContent() != null) {
            log.info("数据验签结果: {}", gatewayResponse.isSignVerifyResult());
            IdentityAuth3Response response = IdentityAuth3Response.fromJsonStr(gatewayResponse.getBizContent());
            log.info("业务数据为: {}", response.toJsonStr());

        }
    }
}
